<template>
	<view class="home b_width">
		<my-searchHome :class="{move:distance}" />
		<!-- banner图 -->
		<view class="banner">
			<swiper class="swiper" indicator-dots="true" autoplay="true" duration="2000" circular="true"
				disable-touch="true">
				<swiper-item v-for="(item, index) in adList" :key="index">
					<image :src="item.image"></image>
				</swiper-item>
			</swiper>
		</view>
		<div class="tc" style="height: 130rpx;"></div>
		<!-- 导航 -->
		<view class="nav">
			<view v-for="(item, index) in navList" :key="index" @click="navUrl(item)">
				<image :src="item.image" mode="aspectFit"></image>
				<text class="hidden width center">{{item.name||item.title}}</text>
			</view>
		</view>
		<!-- 公告 
		<view class="white_b align_center" style="height: 65rpx;margin: 20rpx 30rpx;border-radius: 15rpx;">
			 <image src="../../static/img/news.png" style="width: 200rpx;margin-left: 10rpx;height: 40rpx;"></image> 
			<view class="day_box">最新资讯</view>
			<swiper class="swiper width" autoplay="true" duration="2000" circular="true"
				style="height: 100%;line-height: 65rpx;">
				<swiper-item v-for="(item, index) in noticeList" :key="index">
					<text>{{item.title}}</text>
				</swiper-item>
				<swiper-item v-for="(item, index) in noticeList" :key="index" v-if="noticeList.length==1">
					{{item.title}}
				</swiper-item>
			</swiper>

		</view>-->

		<view class="n_box" v-if="jj">
			<view class="b_flex">
				<view class="jj">公司简介</view>
				<view class="gd" @click="navUrl(jjLm,2)">更多></view>
			</view>
            <view class="gy">
				{{jj.gy}}
			</view>
		</view>

        
       <view class="n_box" v-if="goods">
       	<view class="b_flex">
       		<view class="jj orange">产品推荐</view>
       		<view class="gd" @click="navUrl(goodsLm,2)">更多></view>
       	</view>
           <view class="goods_img" @click="toInfo(goods)">
			   
			   <image mode="widthFix" :src="goods.image"></image>
       		
       	</view>
       </view>
       

       <view class="n_box" v-if="jj">
       	<view class="b_flex">
       		<view class="jj">最新动态</view>
       		<view class="gd" @click="navUrl(newLm,2)" >更多></view>
       	</view>
           <view class="new_box">
       		  <view class="new_info" @click="toInfo(item)" v-for="(item,index) in newList" :key="index">
				  <image mode="widthFix" class="new_img" :src="item.image"></image>
				  <view class="new_right">
					  <view class="new_title">{{item.title}}</view>
					  <view class="new_time">{{item.createtime}}</view>
				  </view>
			  </view>
       	</view>
       </view>

          <view style="height:25rpx;"></view>

       <bottom value="首页"></bottom>

	</view>
</template>

<script>
	const app = getApp().globalData;
	const {
		imgRemote
	} = app;
	import uCountDown from "uview-ui/components/u-count-down/u-count-down.vue";

 import bottom from "@/components/bottom.vue";
	export default {
		components: {
			uCountDown,bottom
		},
		data() {
			return {
				support: false,
				showTop: false,
				token: '',
				imgRemote: imgRemote,
				adList: [],
				navList: [],
				distance: '',
				shareInfo1: '',
				shareInfo2: '',
				jj:'',
				jjLm:'',
				goods:'',
				goodsLm:'',
				newList:[],
				newLm:''
			};
		},
		onLoad(e) {
			 uni.hideTabBar();
			let _ = this;
			let str2 = ['首页分享标题', '首页分享图片'];
			this.$get(this.$api.configLists, {
				name: '首页分享标题'
			}, (res) => {
				if (res.data.code == 1) {
					// arr2.push(res.data.data[0].value);
					this.shareInfo1 = res.data.data[0].value;
				}
			});
			this.$get(this.$api.configLists, {
				name: '首页分享图片'
			}, (res) => {
				if (res.data.code == 1) {
					// arr2.push(res.data.data[0].value);
					_.shareInfo2 = res.data.data[0].value;
					console.log(res)
				}
			});

			let seller_id = '';
			if (e.q) {
				var scene = decodeURIComponent(e.q);
				seller_id = scene.substring(scene.indexOf('1') + parseInt(1));
			} else {
				seller_id = e.id;
			}
			uni.setStorageSync('seller_id', seller_id)
			this.indexMainAd();
			this.indexMainCate();
			
			this.adcateList();
            this.getJj();
			this.getGoods();
			this.getNew();
			
		},
		onShow() {},
		methods: {
			toInfo(e){
			uni.navigateTo({
				url:'/pages/news/info?id='+e.id
			})	
			},
			getNew(){
				this.$get(this.$api.newsJj,{type:3},res=>{
					 let data=res.data;
					 if(data.code==1){
						 this.newList=data.data;
						 this.newLm=data.msg;
					 }
				});
			},
			getGoods(){
				this.$get(this.$api.newsJj,{type:2},res=>{
					 let data=res.data;
					 if(data.code==1){
						 this.goods=data.data;
						 this.goodsLm=data.msg;
					 }
				});
			},
            getJj(){
				this.$get(this.$api.newsJj,{},res=>{
					 let data=res.data;
					 if(data.code==1){
						 this.jj=data.data;
						 this.jjLm=data.msg;
					 }
				});
			},
			telphone() {
				let phone = this.tel;
				uni.makePhoneCall({
					phoneNumber: phone
				});
			},
			memberInfo() {
				let params = {
					token: uni.getStorageSync('userToken')
				}
				this.$get(this.$api.userInfo, params, (res) => {
					let {
						data
					} = res;
					if (data.code == 1) {
						this.personInfo = data.data;
					}
				})
			},
			adcateList() {
				this.$get(this.$api.aLan, {}, (res) => {
					let {
						data
					} = res;
					if (data.code == 1) {
						this.navList = data.data;
					}
				})
			},
			limitPage() {
				uni.navigateTo({
					url: '/pages/indexNav/activeLimit?title=' + this.activity.name
				})
			},
            
			//导航页面
			navUrl(e, index=1) {
				
				if(index==1){
					uni.navigateTo({
						url:'/pages/tabar/food?id='+e.cate_id+'&title='+e.title
					})
				}else{
					uni.navigateTo({
						url:'/pages/tabar/food?id='+e.pid+'&title='+e.title+'&key='+e.id
					})
				}
				
				
			},
			indexMainAd() {
				this.$get(this.$api.aLun, {}, (res) => {
					let {
						data
					} = res;
					console.log(res)
					if (data.code == 1) {
						this.adList = data.data;
					}
				})
			},
			indexMainCate() {
				return;
				this.$get(this.$api.mainCate, {}, res => {
					let data = res.data;
					if (data.code == 1) {
						this.navList = data.data.filter((item, index) => {
							return index < 5
						});
					}
				});
			},
			indexMainRecommend() {
				let _ = this;
				this.$get(this.$api.mainRecommend, {
					city: _.city
				}, res => {
					let data = res.data;
					if (data.code == 1) {

						this.recommendList = data.data;
					} else {
						this.recommendList = [];
						this.$Toast(data.msg);
					}
				});
			},
			indexMainNew() {
				let _ = this;
				this.$get(this.$api.mainNew, {
					city: _.city
				}, res => {
					let data = res.data;
					if (data.code == 1) {
						this.newList = data.data;
					} else {
						this.newList = [];
						this.$Toast(data.msg);
					}
				})
			},
			indexMainNotice() {
				this.$get(this.$api.mainNotice, {}, res => {
					let data = res.data;
					if (data.code == 1) {
						this.noticeList = data.data;
					}
				})
			},
			getLm() {
				this.$get(this.$api.adcateLm, {}, res => {
					let {
						data,
						code
					} = res.data;
					if (code == 1) {
						this.lm = data;
					}
				});
			}
		},

		onShareAppMessage() {
			let obj = {};
			if (this.shareInfo1) {
				obj.title = this.shareInfo1
			}
			if (this.shareInfo2) {
				obj.imageUrl = this.imgRemote + this.shareInfo2
			}
			return obj
		},
		onShareTimeline() {
			if (this.shareInfo1) {
				obj.title = this.shareInfo1
			}
			if (this.shareInfo2) {
				obj.imageUrl = this.imgRemote + this.shareInfo2
			}
			return obj
		}
	};
</script>

<style scoped lang="scss">
	.form_box {
		width: 100%;
		box-sizing: border-box;
		padding: 0 30rpx;
		margin-top: 30rpx;


		image {

			border-radius: 15rpx;
		}
	}

	.home {
		.call-tel {
			position: fixed;
			width: 80rpx;
			height: 80rpx;
			text-align: center;
			display: flex;
			flex-direction: column;
			color: white;
			bottom: 10rpx;
			right: 10rpx;
			background: $b-c;
			border-radius: 50%;
		}

		background: #eee;
		min-height: 100vh;
	}

	.nav {

		//position: relative;
		display: flex;
		flex-wrap: wrap;
		padding: 10rpx 10rpx 25rpx;
		background: white;
		margin: 20rpx 30rpx 0;
		border-radius: 20rpx;
		box-shadow: 1px 1px 4px rgba(0, 0, 0, 0.1);
	}

	::-webkit-scrollbar {
		display: none;
		/* Chrome Safari */
	}

	.nav>view {
		margin-top: 20rpx;
		width: 20%;
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.nav>view text {
		margin-top: 15rpx;
		font-size: 24rpx;
	}



	.nav>view image {
		width: 80rpx;
		height: 80rpx;
		border-radius: 25rpx;
	}

	.banner4 {
		margin: 10rpx 20rpx 0;
		height: 200rpx;
		background: white;
	}

	.banner4 image {
		width: 100%;
		height: 200rpx;
	}

	.home .limit_buy .icon-jiantou {
		font-size: 20rpx;
		height: 32rpx;
		line-height: 32rpx;
	}

	.whole::-webkit-scrollbar {
		width: 0;
		display: none;
	}


	.banner {
		background: linear-gradient(#4ac364, #eee);
		box-sizing: border-box;
		padding: 10rpx 30rpx 0 30rpx;
		height: 200rpx;

		image {
			width: 100%;
			height: 100%;
			border-radius: 15rpx;
		}
	}

	.swiper {
		height: 320rpx;
		font-size: 28rpx;

	}

	.swipers {
		height: 100%;
	}

	.home /deep/ .move .my_search {
		background: #4ac364;
		opacity: 1;
		animation: 1s;
	}

	.flex {
		display: flex;
		justify-content: space-between;
		width: 100%;
	}

	.b_flex {
		display: flex;
		align-items: center;
	}

    .b_flexs {
		display: flex;
	}

	.b_width {
		width: 100%;
		overflow-x: hidden;
	}


	.n_box {
		padding: 10rpx;
		background: white;
		margin: 20rpx 30rpx 0;
		border-radius: 20rpx;
		box-shadow: 1px 1px 4px rgba(0, 0, 0, 0.1);
	}

	.jj {
		color: white;
		box-sizing: border-box;
		padding: 15rpx 0rpx;
		width: 25%;
		text-align: center;
		background-color: #4ac364;
		border-radius: 15rpx 0 0 15rpx;
	}
     .orange{
		 background-color:#F5874A;
	 }
	.gd {
		width: 75%;
		text-align: right;
		background-color: #F0F0EE;
		color: #585858;
		box-sizing: border-box;
		padding: 15rpx 20rpx;
		font-size: 28rpx;
		border-radius: 0 15rpx 15rpx 0rpx;
	}
	.gy{
		box-sizing: border-box;
		padding: 20rpx;
		line-height: 45rpx;
		color: black;
	}
	.goods_img{
		box-sizing: border-box;
		padding: 15rpx 10rpx 0 10rpx;
		image{
			width: 100%;
		}
	}
	.new_img{
		width: 38%;
		height: 140rpx;
		border-radius: 15rpx;
		margin-right: 3%;
	}
	.new_box{
		box-sizing: border-box;
		padding: 10rpx 20rpx 0 20rpx;
	}
	.new_info{
		display: flex;
		box-sizing: border-box;
		padding: 25rpx 0;
		border-bottom: 2rpx solid #EAEAEA;
	}
	.new_right{
		width: 75%;
	}
	.new_title{
		font-size: 30rpx;
		
		text-overflow: -o-ellipsis-lastline;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;

	}
	.new_time{
		font-size: 24rpx;
		color: #9A9A9A;
		margin-top: 15rpx;
	}
</style>